
function Task( callback , delay , total ){

    callback = callback ? callback : null ;
    delay = delay ? delay : 0 ;
    total = total ? total : 0 ;

    let timer = null ;
    let counter = 0 ;

    function operate(){
        // 调用目标函数
        if( typeof( callback ) === 'function' ){
            callback();
        }
        counter++;
        // 判断是否重复执行了指定次数
        if( counter >= total ) {
            clearInterval( timer );
        }
    }

    this.start = function(){
        if( total >= 0 ) {
            // 创建定时器
            timer = setInterval( operate , delay );
        }
    }
}

let fn = function(){
    console.log( '现在时间是: ' + Date.now() );
}

let t = new Task( fn , -500 , -1 );
t.start();
